package com.mitaotao._1_语法._4_循环.单循环;

import java.util.Scanner;

public class _07_求a加aa加aaa加n个a的和 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("为您计算a+aa+aaa+...n个a的和");
        System.out.println("请输入a的值：");
        int a = scanner.nextInt();
        System.out.println("请输入n的值：");
        int n = scanner.nextInt();
        int sum = 0; //定义总和的初始值；
        int jiashu = 0; //定义各个加数的初始值；

        for (int i=1;i<=n;i++){
            // 计算出每个加数的值
            jiashu = jiashu * 10 + a;
            // 计算各个加数的和
            sum += jiashu;

            if (i!=n){
                System.out.print(jiashu+"+");
            }
            else{
                System.out.println(jiashu+"=");
            }
        }
        System.out.print(sum);
        scanner.close();
    }
}
